package com.nbicc.survey.controller;

import com.nbicc.common.ResponseObj;
import com.nbicc.survey.po.EssayQuestionTopic;
import com.nbicc.survey.service.IEssayQuestionTopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@Api(value = "调查问卷 问答题" , description = "问答题管理")
@RestController
@RequestMapping(value = "/survey/essayQuestionTopic")
public class EssayQuestionTopicController {

    @Resource(name = "EssayQuestionTopicServiceImpl")
    private IEssayQuestionTopicService essayQuestionTopicService;

    @ApiOperation(value = "查询")
    @GetMapping("/id/{id}")
    @ResponseBody
    public ResponseObj selectById(@PathVariable String id){
        EssayQuestionTopic essayQuestionTopic = essayQuestionTopicService.selectById(id);
        return ResponseObj.success().setResult(essayQuestionTopic);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @ResponseBody
    public ResponseObj insert(@RequestBody EssayQuestionTopic essayQuestionTopic){
        essayQuestionTopicService.insert(essayQuestionTopic);
        return ResponseObj.success().setResult(essayQuestionTopic);
    }

    @ApiOperation(value = "修改")
    @PutMapping
    @ResponseBody
    public ResponseObj update(@RequestBody EssayQuestionTopic essayQuestionTopic){
        essayQuestionTopicService.updateById(essayQuestionTopic);
        return ResponseObj.success().setResult(essayQuestionTopic);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/id/{id}")
    @ResponseBody
    public ResponseObj delete(@PathVariable String id){
        essayQuestionTopicService.deleteById(id);
        return ResponseObj.success();
    }

    //↑crud========================================================================

    @ApiOperation(value = "获取")
    @PostMapping("/list/questionnaireId/{questionnaireId}")
    @ResponseBody
    public ResponseObj list(@PathVariable String questionnaireId){
        List<EssayQuestionTopic> essayQuestionTopicList = essayQuestionTopicService.selectListByQuestionnaireId(questionnaireId);
        return ResponseObj.success().setResult(essayQuestionTopicList);
    }

}
